﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace job
{
    public partial class company1 : Form
    {
        public company1()
        {
            InitializeComponent();
            Table();                     
        }
        public void Table()
        {
            dataGridView1.Rows.Clear();//清空旧数据
            Dao dao = new Dao();
            string sql = "select * from student_apply";
            IDataReader dc = dao.read(sql); //实例化dc 然后读取一个sql的数据，返回到dc  构造读取结果集
            while (dc.Read()) //一行一行进行读取
            {
                dataGridView1.Rows.Add(dc[0].ToString(), dc[1].ToString(), dc[2].ToString(), dc[3].ToString(), dc[4].ToString());
            }
            dc.Close();
            dao.DaoClose();


        }
       
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

            try
            {
                string id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
            }
            catch
            {
                MessageBox.Show("请先选中一行");
            }
            label2.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();//单击事件获取学号和姓名1
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                label2.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
                string id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();//将值转换为字符串格式，获取学号,可将id换成sno，代表根据学号删除
                label2.Text = id;
                DialogResult dr = MessageBox.Show("确认拒绝吗吗？", "信息提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (dr == DialogResult.OK)
                {
                    string sql = $"delete from  student_apply where sno='{id}'";
                    Dao dao = new Dao();
                    if (dao.Execute(sql) > 0)
                    {
                        MessageBox.Show("拒绝成功");
                        Table();
                    }
                    else
                    {
                        MessageBox.Show("拒绝失败" + sql);
                    }
                    dao.DaoClose();


                }
                Table();
            }
            catch
            {

                MessageBox.Show("请先在表格中选中要删除的学生！", "信息提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
            }
            
        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            DialogResult dr = MessageBox.Show("确认录用吗？", "信息提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
            MessageBox.Show("录用成功");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            company_zhaopin company_Zhaopin = new company_zhaopin();
            company_Zhaopin.ShowDialog();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            company_chaxun admin = new company_chaxun();
            admin.ShowDialog();
        }

        private void 注销ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            login a = new login();
            a.ShowDialog();
            this.Close();
        }

        private void company1_Load(object sender, EventArgs e)
        {

        }
    }
}
